package com.haowu.customer.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.haowu.common.core.domain.R;
import com.haowu.common.core.validate.AddGroup;
import com.haowu.common.core.validate.EditGroup;
import com.haowu.common.core.web.controller.BaseController;
import com.haowu.common.excel.utils.ExcelUtil;
import com.haowu.common.log.annotation.Log;
import com.haowu.common.log.enums.BusinessType;
import com.haowu.common.mybatis.core.page.PageQuery;
import com.haowu.customer.domain.bo.HwAppSocialAuthBo;
import com.haowu.customer.domain.vo.HwAppSocialAuthVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.haowu.customer.service.IHwAppSocialAuthService;
import com.haowu.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 第三方授权登录控制器
 * 前端访问路由地址为:/customer/appSocialAuth
 *
 * @author lky
 * @date 2023-02-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/appSocialAuth")
public class HwAppSocialAuthController extends BaseController {

    private final IHwAppSocialAuthService iHwAppSocialAuthService;

    /**
     * 查询第三方授权登录列表
     */
    @SaCheckPermission("customer:appSocialAuth:list")
    @GetMapping("/list")
    public TableDataInfo<HwAppSocialAuthVo> list(HwAppSocialAuthBo bo, PageQuery pageQuery) {
        return iHwAppSocialAuthService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出第三方授权登录列表
     */
    @SaCheckPermission("customer:appSocialAuth:export")
    @Log(title = "第三方授权登录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HwAppSocialAuthBo bo, HttpServletResponse response) {
        List<HwAppSocialAuthVo> list = iHwAppSocialAuthService.queryList(bo);
        ExcelUtil.exportExcel(list, "第三方授权登录", HwAppSocialAuthVo.class, response);
    }

    /**
     * 获取第三方授权登录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("customer:appSocialAuth:query")
    @GetMapping("/{id}")
    public R<HwAppSocialAuthVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iHwAppSocialAuthService.queryById(id));
    }

    /**
     * 新增第三方授权登录
     */
    @SaCheckPermission("customer:appSocialAuth:add")
    @Log(title = "第三方授权登录", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HwAppSocialAuthBo bo) {
        return toAjax(iHwAppSocialAuthService.insertByBo(bo));
    }

    /**
     * 修改第三方授权登录
     */
    @SaCheckPermission("customer:appSocialAuth:edit")
    @Log(title = "第三方授权登录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HwAppSocialAuthBo bo) {
        return toAjax(iHwAppSocialAuthService.updateByBo(bo));
    }

    /**
     * 删除第三方授权登录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("customer:appSocialAuth:remove")
    @Log(title = "第三方授权登录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iHwAppSocialAuthService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
